﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dynamic.Facades.EntLib.Data;
using System.Data.SqlClient;
using System.Data;

namespace Dynamic.Testing.Web
{
    public partial class GetProduct : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string idd = Request.QueryString["id"];
            string id = idd.Substring(idd.IndexOf("(") + 1, idd.Length - idd.IndexOf("(") - 2);
            Database db = DatabaseFactory.CreateDatabase();
            SqlCommand sqlCom = new SqlCommand();
            sqlCom.CommandType = CommandType.Text;
            sqlCom.CommandText = "select * from dbo.product where cmmf=" + id;

            DataSet dsCustom = db.ExecuteDataSet(sqlCom);
            string s = "";

            foreach (DataRow dr in dsCustom.Tables[0].Rows)
            {
                if (dr["cmmf"] == DBNull.Value || dr["ITEM NO"] == null)
                {
                    continue;
                }

                string desc = dr["Product Description"].ToString().Replace("\"","");
                string price = dr["Unit Price    (USD)"].ToString();
                string ss = string.Format("\"c_txtDesc\": \"{0}\",\"c_txtPrice\": \"{1}\"", desc, price);
                s += ss;

            }
            s = "{" + s + "}";
            Response.Write(s);
        }
    }
}
